package com.baidu.ota.utils;

import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

public final class ProcessUtil {
    private ProcessUtil() {
    }

    public static String getProcessName(Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        if (am == null) {
            return "";
        }
        List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
        if (runningApps == null) {
            return "";
        }
        for (ActivityManager.RunningAppProcessInfo proInfo : runningApps) {
            if (proInfo.pid == android.os.Process.myPid() && proInfo.processName != null) {
                return proInfo.processName;
            }
        }
        return "";
    }
}
